<%@ page import="org.jsecurity.web.filter.authc.FormAuthenticationFilter" %>
<%@include file="/WEB-INF/pages/commons/commons.jsp" %>

<stripes:layout-render name="${_themePath}/basic-layout-without-navbar.jsp" _title="Profile">

    <stripes:layout-component name="_head">
        <script type="text/javascript">
            // === _profileHeaderMenu
                YAHOO.util.Event.onContentReady("_profileHeaderMenu", function() {
                    var _manageHeaderMenu = new YAHOO.widget.Button("_profileHeaderMenuButton",
                                            { type: "menu", menu: "_profileHeaderMenuButtonSelect" });
                    //	"click" event listener for the second Button's Menu instance
                    var onMenuClick = function (p_sType, p_aArgs) {
                        var oEvent = p_aArgs[0];	//	DOM event
                        var oMenuItem = p_aArgs[1];	//	MenuItem instance that was the
                                                    //	target of the event
                        if (oMenuItem) {
                            if ('0' == oMenuItem.value) {   // edit profile
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.user.EditProfileActionBean" event="view" />
                                document.location.href = '${url}';
                            }
                            else if ('1' == oMenuItem.value) { // change password
                                <stripes:url var="url" beanclass="foo.bar.wiki.web.action.user.ChangeProfilePasswordActionBean" event="view" />
                                document.location.href = '${url}';
                            }
                            else {
                                alert('unrecognized menu option');
                            }
                        }
                    };
                    //	Add a "click" event listener for the Button's Menu
                    _manageHeaderMenu.getMenu().subscribe("click", onMenuClick);
                });
        </script>
    </stripes:layout-component>



    <stripes:layout-component name="_topNav">
        <H1>Profile</H1>
        <UL class="gc-topnav-tabs">
            <LI>
                <span id="_profileHeaderMenu">
                <input type="button" id="_profileHeaderMenuButton" value="Options"/>
                <select id="_profileHeaderMenuButtonSelect">
                    <jsecurity:hasPermission name="user:ownProfile:${actionBean.user.id}">
                        <option value="0">Edit Profile</option>
                        <option value="x">&nbsp;</option>
                        <option value="1">Change Password</option>
                    </jsecurity:hasPermission>
                </select>
                </span>
            </LI>
        </UL>
    </stripes:layout-component>

    <stripes:layout-component name="_content">
        <h2>Description [<a id="_showDescription" href="#">Show</a>/<a id="_hideDescription" href="#">Hide</a>]</h2>
        <div id="_description">
            Alter your profile here. Currently only email address is alterable.
            <p/>
            <p/>
            <p/>
        </div>


        <jsecurity:authenticated>
            <h2>${_user.username}'s Profile</h2>

            <stripes:messages />

            <jsecurity:hasPermission name="user:ownProfile:${actionBean.user.id}">
            <stripes:form beanclass="foo.bar.wiki.web.action.user.EditProfileActionBean" method="POST">
            <stripes:errors/>
            <table width="100%">
                <tr>
                    <td>Email:</td>
                    <td><stripes:text name="user.email" /></td>
                </tr>
                <tr>
                    <td colspan="2">
                        <stripes:submit name="save">Save</stripes:submit>        
                    </td>
                </tr>
            </table>
            </stripes:form>
            </jsecurity:hasPermission>
            <p/>
        </jsecurity:authenticated>

        <jsecurity:notAuthenticated>
            Not authenticated ... profile is only valid after authentication.
        </jsecurity:notAuthenticated>
    </stripes:layout-component>

</stripes:layout-render>
